//
//  BaseTableViewController.swift
//  weibo1
//
//  Created by changhongliang on 2017/7/21.
//  Copyright © 2017年 richinfo. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
        // 定义变量保存用户是否登录
        var login:Bool = UserAccount.login()
        var vistorView: VistorView?
        override func loadView(){
            //如果已经登录创建TableView,如果没有登录创建访客视图
            login ? super.loadView() : setupVistor()
        }
    
    
    //创建访客视图
    private func setupVistor(){
        //1.设置访客视图
        vistorView = VistorView()
        view = vistorView
        //2.添加监听方法
        vistorView?.registerButton.addTarget(self, action: #selector(BaseTableViewController.visitorViewDidRegister), for: .touchUpInside)
        
        vistorView?.loginButton.addTarget(self, action: #selector(BaseTableViewController.visitorViewDidLogin), for: .touchUpInside)
        //3.设置导航栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.plain, target: self, action: #selector(BaseTableViewController.visitorViewDidRegister))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.plain, target: self, action: #selector(BaseTableViewController.visitorViewDidLogin))
    }

}


extension BaseTableViewController {
    func visitorViewDidRegister() {
        HLLog("注册")
    }
    
    func visitorViewDidLogin() {
        let navVC = UINavigationController(rootViewController: OAuthViewController())
        self.present(navVC, animated: true, completion: nil)
    }
}

